home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / human interface toolbox / bigscrolling / sample.p < prev   
Encoding:
Text File  |  2000-06-23  |  21.0 KB  |  620 lines

  1. {
  2.     File:        Sample.p
  3.  
  4.     Contains:    ScrollBars are limited in their range to a signed 16-bit number (+/- 32768).
  5.                 This project demo's one way to work around this limitation.
  6.  
  7.     Written by:     
  8.  
  9.     Copyright:    Copyright © 1999 by Apple Computer, Inc., All Rights Reserved.
  10.  
  11.                 You may incorporate this Apple sample source code into your program(s) without
  12.                 restriction. This Apple sample source code has been provided "AS IS" and the
  13.                 responsibility for its operation is yours. You are not permitted to redistribute
  14.                 this Apple sample source code as "Apple sample source code" after having made
  15.                 changes. If you're going to re-distribute the source, we require that you make
  16.                 it clear in the source that the code was descended from Apple sample source
  17.                 code, but that you've made changes.
  18.  
  19.     Change History (most recent first):
  20.                 7/16/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  21.                 
  22.  
  23. }
  24. program Sample;
  25.  
  26. uses
  27.     Traps,Windows,Quickdraw,Devices,Dialogs,BigScrolling,DiskInit;
  28. const {}
  29.  
  30.     kNoEvents = 0; {no events mask}
  31.     kMinHeap = 21 * 1024;      {1.01 - kMinSpace - This is the minimum result from PurgeSpace, when called}
  32.        {     at initialization time, for the application to run. This number acts}
  33.      {      as a double-check to insure that there really is enough memory for the}
  34.          {      application to run, including what has been taken up already by}
  35.      {      pre-loaded resources, the scrap, code, and other sundry memory blocks.}
  36.     kMinSpace = 8 * 1024;  {kExtremeNeg and kExtremePos are used to set up wide open rectangles and regions.}
  37.     kExtremeNeg = -32768;
  38.     kExtremePos = 32767 - 1; {required for old region bug}
  39.  
  40.  {The following constants are all resource IDs, corresponding to resources in Sample.r.}
  41.     rMenuBar = 128; {application's menu bar}
  42.     rAboutAlert = 128; {about alert}
  43.     rUserAlert = 129; {error user alert}
  44.  
  45.  {The following constants are used to identify menus and their items. The menu IDs}
  46.  {      have an "m" prefix and the item numbers within each menu have an "i" prefix.}
  47.     mApple = 128; {Apple menu}
  48.     iAbout = 1;
  49.     mFile = 129; {File menu}
  50.     iQuit = 1;
  51.     mEdit = 130; {Edit menu}
  52.     iUndo = 1;
  53.     iCut = 3;
  54.     iCopy = 4;
  55.     iPaste = 5;
  56.     iClear = 6;  {1.01 - kDITop and kDILeft are used to locate the Disk Initialization dialogs.}
  57.     kDITop = $0050;
  58.     kDILeft = $0070;
  59. var
  60.        {GInBackground is maintained by our osEvent handling routines. Any part of}
  61.  {      the program can check it to find out if it is currently in the background.}
  62.     gInBackground: BOOLEAN; {maintained by Initialize and DoEvent}
  63.     cursorRgn: RgnHandle;  { cursorRgn contains a copy of the last mouseRgn we passed to WaitNextEvent}
  64.  
  65. {$S Main}
  66.  
  67. function IsDAWindow (window: WindowPtr): BOOLEAN;
  68.  
  69.     {Check if a window belongs to a desk accessory.}
  70.  
  71.     begin
  72.         if window = nil then
  73.             IsDAWindow := FALSE
  74.         else {DA windows have negative windowKinds}
  75.             IsDAWindow := (WindowPeek(window)^.windowKind < 0);
  76.     end; {IsDAWindow}
  77.  
  78.     {$S Main}
  79.  
  80. function IsAppWindow (window: WindowPtr): BOOLEAN;
  81.  
  82.     {Check to see if a window belongs to the application. If the window pointer}
  83.     { passed was NIL, then it could not be an application window. WindowKinds}
  84.     { that are negative belong to the system and windowKinds less than userKind}
  85.     { are reserved by Apple except for windowKinds equal to dialogKind, which}
  86.     { mean it is a dialog.}
  87.     { 1.02 - In order to reduce the chance of accidentally treating some window}
  88.  { as an AppWindow that shouldn't be, we'll only return true if the windowkind}
  89.     { is userKind. If you add different kinds of windows to Sample you'll need}
  90.     { to change how this all works.}
  91.  
  92.     begin
  93.         if window = nil then
  94.             IsAppWindow := FALSE
  95.         else {application windows have windowKinds = userKind (8)}
  96.             with WindowPeek(window)^ do
  97.                 IsAppWindow := (windowKind = userKind);
  98.     end; {IsAppWindow}
  99.  
  100.     {$S Main}
  101.  
  102. {$Z+}
  103.  {for trafficlights.p}
  104.  
  105. procedure AlertUser;
  106.  
  107. {Display an alert that tells the user an error occurred, then exit the program.}
  108. { This routine is used as an ultimate bail-out for serious errors that prohibit}
  109. { the continuation of the application. Errors that do not require the termination}
  110. { of the application should be handled in a different manner. Error checking and}
  111. { reporting has a place even in the simplest application. For simplicity, the alert}
  112. { displayed here only says that an error occurred, but not what it was. There are}
  113.     { various methods available for being more specific.}
  114.  
  115.     var
  116.         itemHit: integer;
  117.  
  118.     begin
  119.         SetCursor(qd.arrow);
  120.         itemHit := Alert(rUserAlert, nil);
  121.         ExitToShell;
  122.     end; {AlertUser}
  123.  
  124.     {$S Main}
  125.  
  126. function DoCloseWindow (window: WindowPtr): BOOLEAN;
  127.  
  128.     {Close a window.}
  129.  
  130.     {1.01 - At this point, if there was a document associated with a}
  131.     { window, you could do any document saving processing if it is 'dirty'.}
  132.     { DoCloseWindow would return TRUE if the window actually closes, i.e.,}
  133.     { the user does not cancel from a save dialog. This result is handy when}
  134.     { the user quits an application, but then cancels a save of a document}
  135.     { associated with a window. We also added code to close the application}
  136.   { window since otherwise, the termination routines would never stop looping,}
  137.     { waiting for FrontWindow to return NIL.}
  138.  
  139.     begin
  140.         DoCloseWindow := TRUE;
  141.         if IsDAWindow(window) then
  142.             begin
  143.                 CloseDeskAcc(WindowPeek(window)^.windowKind);
  144.             end
  145.         else if IsAppWindow(window) then
  146.             begin
  147.                 CloseAppWindow(window);
  148.             end
  149.     end; {DoCloseWindow}
  150.  
  151.     {$S Initialize}
  152.  
  153. procedure Initialize;
  154.  
  155.     {Set up the whole world, including global variables, Toolbox managers,}
  156.     { and menus. We also create our one application window at this time.}
  157.  
  158.     { If a failure occurs here, we will consider that the application is in such}
  159.     { bad shape that we should just exit. Your error handling may differ, but}
  160.     { the checks should still be made.}
  161.  
  162.  
  163.     var
  164.         menuBar: Handle;
  165.         total, contig: LongInt;
  166.  
  167.     begin
  168.         gInBackground := FALSE;
  169.  
  170.         InitGraf(@qd.thePort);
  171.         InitFonts;
  172.         InitWindows;
  173.         InitMenus;
  174.         TEInit;
  175.         InitDialogs(nil);
  176.         InitCursor;
  177.  
  178. {1.01 - We used to make a check for memory at this point by examining ApplLimit,}
  179. {      ApplicZone, and StackSpace and comparing that to the minimum size we told}
  180. {      MultiFinder we needed. This did not work well because it assumed too much about}
  181. {      the relationship between what we asked MultiFinder for and what we would actually}
  182. {      get back, as well as how to measure it. Instead, we will use an alternate}
  183.             {      method comprised of two steps.}
  184.  
  185.  {It is better to first check the size of the application heap against a value}
  186. {      that you have determined is the smallest heap the application can reasonably}
  187. {      work in. This number should be derived by examining the size of the heap that}
  188. {      is actually provided by MultiFinder when the minimum size requested is used.}
  189. {      The derivation of the minimum size requested from MultiFinder is described}
  190. {      in Sample.h. The check should be made because the preferred size can end up}
  191. {      being set smaller than the minimum size by the user. This extra check acts to}
  192.  {     insure that your application is starting from a solid memory foundation.}
  193.  
  194.         if ORD(GetApplLimit) - ORD(ApplicationZone) < kMinHeap then
  195.             AlertUser;
  196.  
  197.     {Next, make sure that enough memory is free for your application to run. It}
  198. {      is possible for a situation to arise where the heap may have been of required}
  199. {      size, but a large scrap was loaded which left too little memory. To check for}
  200. {      this, call PurgeSpace and compare the result with a value that you have determined}
  201. {      is the minimum amount of free memory your application needs at initialization.}
  202. {      This number can be derived several different ways. One way that is fairly}
  203. {      straightforward is to run the application in the minimum size configuration}
  204. {      as described previously. Call PurgeSpace at initialization and examine the value}
  205. {      returned. However, you should make sure that this result is not being modified}
  206. {      by the scrap's presence. You can do that by calling ZeroScrap before calling}
  207.          {     PurgeSpace. Make sure to remove that call before shipping, though.}
  208.  
  209.         PurgeSpace(total, contig);
  210.         if total < kMinSpace then
  211.             AlertUser;
  212.  
  213. {The extra benefit to waitng until after the Toolbox Managers have been initialized}
  214. {      before checking memory is that we can now give the user an alert to tell him what}
  215. {      happened. Although it is possible that the memory situation could be worsened by}
  216. {      displaying an alert, MultiFinder would gracefully exit the application with}
  217.   {     an informative alert if memory became critical. Here we are acting more}
  218. {      in a preventative manner to avoid future disaster from low-memory problems.}
  219.  
  220.         menuBar := GetNewMBar(rMenuBar); {read menus into menu bar}
  221.         if menuBar = nil then
  222.             AlertUser;
  223.         SetMenuBar(menuBar); {install menus}
  224.         DisposeHandle(menuBar);
  225.         AppendResMenu(GetMenuHandle(mApple), 'DRVR'); {add DA names to Apple menu}
  226.         DrawMenuBar;
  227.  
  228. {     InitializeApplication is a call to another unit (BigScrolling.p in this case).  This is}
  229. {     here so you can put any application-specific code where it belongs instead of in the main }
  230. {     program all the time.    }
  231.  
  232.         InitializeApplication; { give some other unit the chance to initialize}
  233. {                                            itself }
  234.  
  235.     end; {Initialize}
  236.  
  237.     {$S Main}
  238.  
  239. procedure Terminate;
  240.  
  241.     {Clean up the application and exits. We close all of the windows so that}
  242.     { they can update their documents, if any.}
  243.  
  244.     {1.01 - If we find out that a cancel has occurred, we won't exit to the}
  245.     { shell, but will return instead.}
  246.  
  247.     var
  248.         aWindow: WindowPtr;
  249.         closed: BOOLEAN;
  250.  
  251.     begin
  252.         closed := TRUE;
  253.         repeat
  254.             aWindow := FrontWindow; {get the current front window}
  255.             if aWindow <> nil then
  256.                 closed := DoCloseWindow(aWindow); {close}
  257. {                    this window}
  258.         until (not closed) | (aWindow = nil); {do all windows}
  259.  
  260. {     TerminateApplication is a call to another unit (TrafficLights.p in the case of Sample).    This is}
  261. {     here so you can put any application-specific code where it belongs instead of in the main }
  262.             {     program all the time.    }
  263.  
  264.         TerminateApplication; { give some other unit the chance to kill itself}
  265. {                                          }
  266.  
  267.         if closed then
  268.             ExitToShell; {exit if no cancellation}
  269.     end; {Terminate}
  270.  
  271.     {$S Main}
  272.  
  273. procedure AdjustMenus;
  274.  
  275.     {Enable and disable menus based on the current state.}
  276.     { The user can only select enabled menu items. We set up all the menu items}
  277.     { before calling MenuSelect or MenuKey, since these are the only times that}
  278.     { a menu item can be selected. Note that MenuSelect is also the only time}
  279.     { the user will see menu items. This approach to deciding what enable/}
  280. { disable state a menu item has the advantage of concentrating all the decision-}
  281. { making in one routine, as opposed to being spread throughout the application.}
  282. { Other application designs may take a different approach that may or may not be}
  283.     { just as valid.}
  284.  
  285. { 9/12/91, (MD) -- Added enabling and disabling page setup and print around DA windows. }
  286.  
  287.     var
  288.         window: WindowPtr;
  289.         menu: MenuHandle;
  290.  
  291.     begin
  292.         window := FrontWindow;
  293.  
  294.         menu := GetMenuHandle(mEdit);
  295.         if IsDAWindow(window) then
  296.             begin {a desk accessory might need the edit}
  297. {                                                         menu}
  298.                 EnableItem(menu, iUndo);
  299.                 EnableItem(menu, iCut);
  300.                 EnableItem(menu, iCopy);
  301.                 EnableItem(menu, iPaste);
  302.                 EnableItem(menu, iClear);
  303.             end
  304.         else
  305.             begin {but we know we do not}
  306.                 DisableItem(menu, iUndo);
  307.                 DisableItem(menu, iCut);
  308.                 DisableItem(menu, iCopy);
  309.                 DisableItem(menu, iClear);
  310.                 DisableItem(menu, iPaste);
  311.             end;
  312.  
  313.     end; {AdjustMenus}
  314.  
  315.     {$S Main}
  316.  
  317. procedure DoMenuCommand (menuResult: LongInt);
  318.  
  319.     {This is called when an item is chosen from the menu bar (after calling}
  320.     { MenuSelect or MenuKey). It performs the right operation for each command.}
  321.     { It is good to have both the result of MenuSelect and MenuKey go to}
  322.     { one routine like this to keep everything organized.}
  323.  
  324.     var
  325.         menuID: integer; {the ID of the selected menu}
  326.         menuItem: integer; {the item number of the selected menu}
  327.         itemHit: integer;
  328.         daName : Str255;
  329.         daRefNum: integer;
  330.         handledByDA: BOOLEAN;
  331.  
  332.     begin
  333.         menuID := HiWrd(menuResult); {use built-ins (for efficiency)...}
  334.         menuItem := LoWrd(menuResult); {to get menu item number and menu}
  335. {                                                      number}
  336.         case menuID of
  337.             mApple: 
  338.                 case menuItem of
  339.                     iAbout: {bring up alert for About}
  340.                         itemHit := Alert(rAboutAlert, nil);
  341.                     otherwise
  342.                         begin {all non-About items in this menu are DAs}
  343.                             GetMenuItemText(GetMenuHandle(mApple), menuItem, daName);
  344.                             daRefNum := OpenDeskAcc(daName);
  345.                         end;
  346.                 end;
  347.             mFile: 
  348.                 case menuItem of
  349.                     iQuit: 
  350.                         Terminate;
  351.                 end;
  352.             mEdit: {call SystemEdit for DA editing & MultiFinder}
  353.                 handledByDA := SystemEdit(menuItem - 1); {since we don't do any}
  354. {                                                                            editing}
  355.             otherwise
  356.                 ;        { The System takes care of Apple, Help and Application menus for us when we call}
  357. {                                       MenuSelect, but it's good form to have all cases covered with a statement. }
  358.         end;
  359.         HiliteMenu(0); {unhighlight what MenuSelect (or MenuKey) hilited}
  360.     end; {DoMenuCommand}
  361.  
  362.     {$S Main}
  363.  
  364. procedure DoUpdate (window: WindowPtr);
  365.  
  366.     {This is called when an update event is received for a window.}
  367.     { It calls DrawWindow to draw the contents of an application window.}
  368.     { As an effeciency measure that does not have to be followed, it}
  369.     { calls the drawing routine only if the visRgn is non-empty. This}
  370.     { will handle situations where calculations for drawing or drawing}
  371.     { itself is very time-consuming.}
  372.  
  373.     begin
  374.         if IsAppWindow(window) then
  375.             begin
  376.                 BeginUpdate(window); {sets up the visRgn, clears updateRgn}
  377.                 if not EmptyRgn(window^.visRgn) then {draw if updating needs to be}
  378. {                                                                  done}
  379.                     DrawWindow(window, nil, FALSE, window = FrontWindow); {when we update,}
  380. {                    we're not printing}
  381.                 EndUpdate(window); {restores the visRgn}
  382.             end;
  383.     end; {DoUpdate}
  384.  
  385.     {$S Main}
  386.  
  387. procedure DoActivate (window: WindowPtr; becomingActive: BOOLEAN);
  388.  
  389.     {This is called when a window is activated or deactivated.}
  390.     { In Sample, the Window Manager's handling of activate and}
  391.     { deactivate events is sufficient. Other applications may have}
  392.     { TextEdit records, controls, lists, etc., to activate/deactivate.}
  393.  
  394.     begin
  395.         if IsAppWindow(window) then
  396.             DrawWindow(window, nil, FALSE, becomingActive);
  397.     end; {DoActivate}
  398.  
  399.     {$S Main}
  400.  
  401. procedure GetGlobalMouse (var mouse: point);
  402.  
  403.     {Get the global coordinates of the mouse. When you call OSEventAvail}
  404.     { it will return either a pending event or a null event. In either case,}
  405.     { the where field of the event record will contain the current position}
  406.     { of the mouse in global coordinates and the modifiers field will reflect}
  407.     { the current state of the modifiers. Another way to get the global}
  408.     { coordinates is to call GetMouse and LocalToGlobal, but that requires}
  409.     { being sure that thePort is set to a valid port.}
  410.  
  411.     var
  412.         event: EventRecord;
  413.  
  414.     begin
  415.         if OSEventAvail(kNoEvents, event) then
  416.             ; {we aren't interested in any}
  417. {                                                                 events}
  418.         mouse := event.where; {just the mouse position}
  419.     end;
  420.  
  421.     {$S Main}
  422.  
  423. procedure AdjustCursor (mouse: point);
  424.  
  425. {Change the cursor's shape, depending on its position. This also calculates the region}
  426. { where the current cursor resides (for WaitNextEvent). If the mouse is ever outside of}
  427.  { that region, an event is generated, causing this routine to be called. This}
  428.   { allows us to change the region to the region the mouse is currently in. If}
  429. { there is more to the event than just “the mouse moved”, we get called before the}
  430. { event is processed to make sure the cursor is the right one. In any (ahem) event,}
  431.     { this is called again before we fall back into WNE.}
  432.  
  433.     var
  434.         window: WindowPtr;
  435.         arrowRgn: RgnHandle;
  436.         plusRgn: RgnHandle;
  437.  
  438.     begin
  439.         window := FrontWindow; {we only adjust the cursor when we are in}
  440. {                                            front}
  441.         if (not gInBackground) and (not IsDAWindow(window)) then
  442.             begin
  443.                 {calculate regions for different cursor shapes}
  444.                 arrowRgn := NewRgn;
  445.                 plusRgn := NewRgn;
  446.  
  447.                 {start with a big, big rectangular region}
  448.                 {1.01 - changed to kExtremeNeg and kExtremePos for consistency}
  449.                 SetRectRgn(arrowRgn, kExtremeNeg, kExtremeNeg, kExtremePos, kExtremePos);
  450.  
  451.                 {calculate plusRgn}
  452. { In previous versions of Sample, this routine was significantly more complicated than}
  453. { it is now.  It used to create a rectangular region based on a window's portRect, intersect }
  454. {it with the visRgn.  Since the visRgn is in local coordinates and the contentRgn is in global}
  455. {coordinates, this used to be a fair amount of calculation.  All of which was unnecessary, }
  456. {because:  a)  We only do this for our frontmost window, which is always completely visible}
  457. {unless we have some kind of floating window in front of it, and b) we can't move the mouse}
  458. {into any part of the content region that's not on-screen.}
  459. {This routine now uses the contentRgn of the frontWindow for the plusRgn, exclusively.}
  460.  
  461.                 if IsAppWindow(window) then
  462.                     CopyRgn(WindowPeek(window)^.contRgn, plusRgn);
  463.  
  464.                 {subtract other regions from arrowRgn}
  465.                 DiffRgn(arrowRgn, plusRgn, arrowRgn);
  466.  
  467.                 {change the cursor and the region parameter}
  468.                 if PtInRgn(mouse, plusRgn) then
  469.                     begin
  470.                         SetCursor(GetCursor(plusCursor)^^);
  471.                         CopyRgn(plusRgn, cursorRgn);
  472.                     end
  473.                 else
  474.                     begin
  475.                         SetCursor(qd.arrow);
  476.                         CopyRgn(arrowRgn, cursorRgn);
  477.                     end;
  478.  
  479.                 {get rid of our local regions}
  480.                 DisposeRgn(arrowRgn);
  481.                 DisposeRgn(plusRgn);
  482.             end;
  483.     end; {AdjustCursor}
  484.  
  485.     {$S Main}
  486.  
  487. procedure DoEvent (event: EventRecord);
  488.  
  489. {Do the right thing for an event. Determine what kind of event it is, and call}
  490.     { the appropriate routines.}
  491.  
  492.     var
  493.         part, err: integer;
  494.         window: WindowPtr;
  495.         key: CHAR;
  496.         aPoint: point;
  497.  
  498.     begin
  499.         case event.what of
  500.             mouseDown: 
  501.                 begin
  502.                     part := FindWindow(event.where, window);
  503.                     case part of
  504.                         inDesk: 
  505.                             ;
  506.                         inMenuBar: 
  507.                             begin {process the menu command}
  508.                                 AdjustMenus;
  509.                                 DoMenuCommand(MenuSelect(event.where));
  510.                             end;
  511.                         inSysWindow: {let the system handle the mouseDown}
  512.                             SystemClick(event, window);
  513.                         inContent: 
  514.                             if window <> FrontWindow then
  515.                                 begin
  516.                                     SelectWindow(window);
  517.                                 {DoEvent(event);}
  518.                                 {use this line for "do first click"}
  519.                                 end
  520.                             else
  521.                                 DoContentClick(window, event);
  522.                         inDrag: 
  523.                             begin
  524.                                 {pass screenBits.bounds to get all gDevices}
  525.                                 DragWindow(window, event.where, qd.screenBits.bounds);
  526.                                 AdjustCursor(event.where);
  527.                             end;
  528.                         inGrow: 
  529.                             ;
  530.                         inZoomIn, inZoomOut: 
  531.                             ;
  532.                     end;
  533.                 end;
  534.             keyDown, autoKey: 
  535.                 begin {check for menukey equivalents}
  536.                     key := CHR(BAND(event.message, charCodeMask));
  537.                     if BAND(event.modifiers, cmdKey) <> 0 then {Command key down}
  538.                         if event.what = keyDown then
  539.                             begin
  540.                                 AdjustMenus; {enable/disable/check menu items properly}
  541.                                 DoMenuCommand(MenuKey(key));
  542.                             end;
  543.                 end; {call DoActivate with the window and...}
  544.             activateEvt: {TRUE for activate, FALSE for deactivate}
  545.                 DoActivate(WindowPtr(event.message), BAND(event.modifiers, activeFlag) <> 0);
  546.             updateEvt: {call DoUpdate with the window to update}
  547.                 DoUpdate(WindowPtr(event.message));
  548.              {1.01 - It is not a bad idea to at least call DIBadMount in response}
  549.                 {            to a diskEvt, so that the user can format a floppy.}
  550.             diskEvt: 
  551.                 if HiWrd(event.message) <> noErr then
  552.                     begin
  553.                         SetPt(aPoint, kDILeft, kDITop);
  554.                         err := DIBadMount(aPoint, event.message);
  555.                     end;
  556.             osEvt: 
  557.                 case BAND(BRotL(event.message, 8), $FF) of {high byte of message}
  558.                     SuspendResumeMessage: 
  559.                         begin
  560.                             gInBackground := BAND(event.message, resumeFlag) = 0;
  561.                             DoActivate(FrontWindow, not gInBackground);
  562.                         end;
  563.                     mouseMovedMessage: 
  564.                         AdjustCursor(event.where);
  565.                 end;
  566.             otherwise
  567.                 ;
  568.         end;
  569.     end; {DoEvent}
  570.  
  571.     {$S Main}
  572.  
  573. procedure EventLoop;
  574.  
  575.     {Get events forever, and handle them by calling DoEvent.}
  576.     { Get the events by calling WaitNextEvent, if it's available, otherwise}
  577.  { by calling GetNextEvent. Also call AdjustCursor each time through the loop.}
  578.  
  579.     var
  580.         gotEvent: BOOLEAN;
  581.         event: EventRecord;
  582.         mouse: point;
  583.  
  584.     begin
  585.         cursorRgn := NewRgn;
  586.         GetGlobalMouse(mouse);   { find the current mouse position }
  587.         AdjustCursor(mouse);  { set up the cursor once }
  588.         repeat
  589. {put us 'asleep' forever under}
  590. {                                                            MultiFinder}
  591.             gotEvent := WaitNextEvent(everyEvent, event, MAXLONGINT, cursorRgn);
  592.  
  593.             if gotEvent then
  594.                 DoEvent(event);
  595.                 {If you are using modeless dialogs that have editText items,}
  596.          {          you will want to call IsDialogEvent to give the caret a chance}
  597.  {          to blink, even if WNE/GNE returned FALSE. However, check FrontWindow}
  598.                 {            for a non-NIL value before calling IsDialogEvent.}
  599.         until FALSE; {loop forever; we quit through an ExitToShell}
  600.     end; {EventLoop}
  601.  
  602.     {This routine is part of the MPW runtime library. This external}
  603.     { reference to it is done so that we can unload its segment, %A5Init.}
  604.  
  605.     {$S Main}
  606.  
  607. begin
  608.  
  609.         {1.01 - call to ForceEnvirons removed}
  610.         {If you have stack requirements that differ from the default,}
  611.         {      then you could use SetApplLimit to increase StackSpace at }
  612.         {      this point, before calling MaxApplZone.}
  613.  
  614.     MaxApplZone; {expand the heap so code segments load at the top}
  615.  
  616.     Initialize; {initialize the program}
  617.     //UnloadSeg(@Initialize); {note that Initialize must not be in Main!}
  618.  
  619.     EventLoop; {call the main event loop}
  620. end.